FROM python:3.9

WORKDIR /app

# 使用国内 apt 源加速构建（兼容 slim 和完整版）
RUN (test -f /etc/apt/sources.list && sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list || true) && \
    (test -f /etc/apt/sources.list.d/debian.sources && sed -i 's|http://deb.debian.org|http://mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources || true) && \
    apt-get update && apt-get install -y libgl1-mesa-glx && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

COPY . /app
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

ENV PYTHONUNBUFFERED=1
ENV PORT=8000

CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT}"]
